﻿package com.gamemeal.graphics {
	/**
	 * @author Colin
	 */
	public class ColorUtils {
		public static function rgb2hsl(r : Number,g : Number,b : Number) : Array {
			var h:Number,s:Number,l:Number;

			r= r/255;
			g= g/255;
			b= b/255;

			var min:Number = Math.min(r,Math.min(g,b));
			var max:Number = Math.max(r,Math.max(g,b));
			var delMax:Number = max-min;

			l = max;
			if(delMax==0)return [0,0,l];

			s = delMax/max;

			var r2:Number = ( ( ( max - r ) / 6 ) + ( delMax / 2 ) ) / delMax;
			var g2:Number = ( ( ( max - g ) / 6 ) + ( delMax / 2 ) ) / delMax;
			var b2:Number = ( ( ( max - b ) / 6 ) + ( delMax / 2 ) ) / delMax;

			if(r == max){
			  	h = b2 - g2;
			}else if (g == max){
			  	h = ( 1 / 3 ) + r2 - b2;
			}else if (b == max){
				h = ( 2 / 3 ) + g2 - r2;
			}
			if (h<0) h++;
			if (h>1) h--;

			return [h,s,l];
		}
		
		
	}
}
